<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Necesario emplearlo con el BaseController, ya que especifica la ruta al template actual
 */
function get_node_meta($node_id, $keta_key = NULL)
{
	$CI =& get_instance();
	$CI->load->Model("Node_Model", "Nodes");
	
	$cache_time = intval($CI->settings->item("_site_cache_nodes_time"));
	
	$node_metas = $CI->mp_cache->model("Nodes", "getMeta", array($node_id, $keta_key), $cache_time);
	
	return $node_metas;	
}

function get_node_hit($node_id, $hit_key = NULL){
	$CI =& get_instance();
	$CI->load->Model("Node_Model", "Nodes");
	
	$cache_time = intval($CI->settings->item("_site_cache_nodes_time"));
	
	$node_metas = $CI->mp_cache->model("Nodes", "getHit", array($node_id, $hit_key), $cache_time);
	
	return $node_metas;	
}

function get_node_categories($node_id){
	$CI =& get_instance();
	$CI->load->Model("Node_Model", "Nodes");
	
	$cache_time = intval($CI->settings->item("_site_cache_nodes_time"));
	
	$node_metas = $CI->mp_cache->model("Nodes", "getCategories", array($node_id, $keta_key), $cache_time);
	
	return $node_metas;	
}

function get_nodes($params){
	$CI =& get_instance();
	$CI->load->Model("Node_Model", "Nodes");
	
	$cache_time = intval($CI->settings->item("_site_cache_nodes_time"));
	
	$node_metas = $CI->mp_cache->model("Nodes", "get", array($params), $cache_time);
	
	return $node_metas;	
}

function get_image_path($data, $image_field, $image_thumbnail_name = NULL){
	$path = NULL;
	
	if($data != NULL && isset($data[$image_field])){
		if(is_array($data[$image_field])){
			$image = $data[$image_field][0];
		} else{
			$image = $data[$image_field];
		}
		
		$path = $image['path'];
		
		if($image_thumbnail_name != NULL && isset($image['thumbnails']) && isset($image['thumbnails'][$image_thumbnail_name])){
			$path = $image['thumbnails'][$image_thumbnail_name]['path'];
		}
	}
	
	return $path;
}

function get_node_url($node){
	$url = NULL;
	if($node != NULL){
		$url = "/juego/{$node->url_name}";
	}
	
	return $url;
}

function get_category_url($category){
	$url = NULL;
	if($category != NULL){
		$url = "/categoria/{$category->url_name}";
	}
	
	return $url;
}

function get_date_format($date, $format = "%d/%m/%Y"){
	return mdate($format, mysql_to_unix($date));
}

function get_datetime_format($date, $format = "%d/%m/%Y %H:%i"){
	return mdate($format, mysql_to_unix($date));
}
